//  所在包名
package com.example.pagesldertablistdemo.slice;
// 引入模块
import com.example.pagesldertablistdemo.ResourceTable;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextAlignment;
import ohos.app.Context;
import java.util.List;
// 数据源类
public class MainAbilityProvider extends PageSliderProvider {
    // 数据列表
    private List<String> dataList;
    // 上下文
    private Context context;
    // 构造方法
    public MainAbilityProvider(List<String> dataList,  Context context) {
        this.dataList = dataList;
        this.context = context;
    }
    // 子页面个数
    @Override
    public int getCount() {
        return dataList.size();
    }
    // 定义子页面内容
    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        Text label = new Text(null);
        label.setTextAlignment(TextAlignment.CENTER);
        label.setLayoutConfig(
                new StackLayout.LayoutConfig(
                        ComponentContainer.LayoutConfig.MATCH_PARENT,
                        ComponentContainer.LayoutConfig.MATCH_PARENT
                ));
        label.setText(dataList.get(i));
        label.setTextColor(Color.BLACK);
        label.setTextSize(100);
        label.setMarginsLeftAndRight(24, 24);
        label.setMarginsTopAndBottom(24, 24);
        ShapeElement element = new ShapeElement(context, ResourceTable.Graphic_background_ability_main);
        label.setBackground(element);
        componentContainer.addComponent(label);
        return label;
    }
    // 移除绑定的对象
    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);
    }
    // 是否绑定对象
    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }
}
